﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Jewelnoid
{
    class Object2D
    {
        public Texture2D texture;
        public Rectangle rect;
        public Vector2 position;
        public Vector2 pivot;
        public Color color;
        public Vector2 scale;
        public float rotation;
        public float alpha;

        public Object2D(Texture2D texture, Vector2 position, Color color)
        {
            this.texture = texture;
            this.position = position;
            this.color = color;

            rotation = 0;
            alpha = 1f;
            scale = new Vector2(1, 1);
            pivot = new Vector2(texture.Width / 2, texture.Height / 2);

            this.rect = new Rectangle((int)(position.X - texture.Width / 2), (int)(position.Y - texture.Height / 2), texture.Width, texture.Height);
        }

        public virtual void draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(this.texture, this.position, null, this.color * alpha, this.rotation, this.pivot, this.scale, SpriteEffects.None, 0.5f);
            //spriteBatch.Draw(this.texture, this.rect, Color.Yellow);  //Desenha o retângulo de colisão.
        }

        public virtual void updateRect()
        {
            this.rect.X = (int)this.position.X - this.rect.Width / 2;
            this.rect.Y = (int)this.position.Y - this.rect.Height / 2;
        }

        public Boolean checkCollision(Object2D obj)
        {
            return this.rect.Intersects(obj.rect);
        }
    }
}
